import logging
import time
# # logging.basicConfig(stream='1.log',
#                     level=logging.INFO,
#                     format='%(asctime)s -%(name)s - %(levelname)s- %(module)s:  %(message)s')

# 自定义获取一个日志logger
log = logging.getLogger('test')

# 设置一个文件输出流及等级
filehandle = logging.FileHandler('1.log', encoding='utf-8')  # 写入日志文件 注意需要设置编码格式
filehandle.setLevel(logging.INFO)

# 输出屏幕
stream = logging.StreamHandler()
stream.setLevel(logging.ERROR)

# 配置一个日志输出格式
formater = logging.Formatter('%(asctime)s -%(name)s - %(levelname)s- %(module)s:  %(message)s')


# 将格式与输出流关联
filehandle.setFormatter(formater)
stream.setFormatter(formater)

log.addHandler(filehandle)
log.addHandler(stream)

# # 程序正常日志
# log.debug("我是debug日志")
# log.info("我是info日志")
#
# # 程序出现问题时记录的日志
# log.warning("我是warning日志")
# log.error("我是error日志")
# log.critical("我是立即需要解决的BUG,致命性")

print(time.strftime("%Y-%m-%d %H:%M:%S"))


